//This Implementation features a matrix made of a array of rows.
//Each row is represente by a number each bit of that number represents on cell
// shift operator seems limited, so i have only 16 bits :-(

matrix
	var/list/rows
	var/columns
	var/num_row		//not realy neede but meh, performance...

	//Constructor for a homogene matrix
	New(rows as num, columns as num, value as num){
		src.rows = new/list()
		for(var/i = 0, i < rows, i++){
			if(value){	//true or false
				src.rows.Add((2**columns)-1)	//bitpattern 1111111...1111111
			}else{
				src.rows.Add(0) 				//bitpattern 0000000000000000
			}
		}
		num_row = rows
		src.columns = columns
	}
	//That created the following bitpattern for value = FALSE (0)
	//			1234567......c(number of columns)
	//row1		0000000...0000
	//row2		0000000...0000
	//...		..............
	//row[r]	0000000...0000
	//a list full of 0's which each represents the bitpattern of 16 0's in binary system

	//colums var may come in handy, but is not absolutely neccessary

	proc/print(){
		world << "Matrix:\ncolumns:	[src.columns],	rows:	[src.num_row]"
		for(var/i = 0, i < src.num_row, i++){
			world << src.rows[i+1]
		}
	}

	proc/invertBits(){
		for(var/i = 0, i < num_row, i++){
			src.rows[i+1] ^= ((2**columns)-1) //and'ed with a 1111..111 Pattern, i invert each bit and therefor the whole relevant sequence
		}
	}

	//At least these previous functions seem to be more effective up to now...

	proc/and(var/matrix/M){
		//security check of cause ;-)
		if(src.columns == M.columns && src.num_row == M.num_row){
			var/matrix/R = new/matrix(src.columns,src.num_row,FALSE)
			for(var/i = 0, i < src.num_row, i++){
				//AND'ed and set
				R.rows[i+1] = (src.rows[i+1] & M.rows[i+1])
			}
			return R
		}else{
			world << "ERROR: Matrices are not of the same dimensions."
		}
	}
